const Service = require('egg').Service;

class ClassService extends Service {
  async index() {
    const { app } = this;
  }

  // 添加课程
  async addCourse() {
    const { ctx, app } = this;
    const { course_name } = ctx.request.body;
    const data = await app.mysql.insert('course_info', {
      course_name
    })
    return { code: 0, data }
  }
  // 查询课程接口
  async findCourse() {
    const { app } = this;
    const data = await app.mysql.select('course_info')
    return { code: 0, data }
  }

  // 添加教室
  async addRoom() {
    const { ctx, app } = this;
    const { room_id } = ctx.request.body;
    const data = await app.mysql.insert('room_info', {
      room_id
    })
    return { code: 0, data }
  }
  // 查询教室接口
  async findRoom() {
    const { ctx, app } = this;
    const data = await app.mysql.select('room_info')
    return { code: 0, data }
  }

  // 添加班级信息接口  根据查询到的课程和教室
  async addClassGrade() {
    const { ctx, app } = this;
    /** grade_name：班级，course_name：课程，classroom:教室  */
    const { grade_name, course_name, classroom } = ctx.request.body;
    const data = await app.mysql.insert('room_info', {
      grade_name, course_name, classroom
    })
    return { code: 0, data }
  }
}

module.exports = ClassService;